const noop = () => {
};

/* eslint-disable */
module.exports = function (redisClient, module) {
    const helpers = module.helpers.redis;

    module.setAdd = function (key, value, callback = noop) {
        if (!Array.isArray(value)) {
            value = [value];
        }
        if (!value.length) {
            return callback();
        }
        redisClient.sadd(key, value, callback);
    };

    module.setsAdd = (keys, value, callback = noop) => helpers.multiKeysValue(redisClient, 'sadd', keys, value, callback);

    module.setRemove = function (key, value, callback = noop) {
        redisClient.srem(key, value, callback);
    };

    module.setsRemove = function (keys, value, callback = noop) {
        helpers.multiKeysValue(redisClient, 'srem', keys, value, callback);
    };

    module.isSetMember = function (key, value, callback = noop) {
        redisClient.sismember(key, value, (err, result) => {
            callback(err, result === 1);
        });
    };

    module.isSetMembers = function (key, values, callback = noop) {
        helpers.multiKeyValues(redisClient, 'sismember', key, values, (err, results) => {
            callback(err, results ? helpers.resultsToBool(results) : null);
        });
    };

    module.isMemberOfSets = function (sets, value, callback = noop) {
        helpers.multiKeysValue(redisClient, 'sismember', sets, value, (err, results) => {
            callback(err, results ? helpers.resultsToBool(results) : null);
        });
    };

    module.getSetMembers = function (key, callback) {
        redisClient.smembers(key, callback);
    };

    module.getSetsMembers = function (keys, callback) {
        helpers.multiKeys(redisClient, 'smembers', keys, callback);
    };

    module.setCount = (key, callback) => redisClient.scard(key, callback);

    module.setsCount = (keys, callback) => helpers.multiKeys(redisClient, 'scard', keys, callback);

    module.setRemoveRandom = (key, callback = noop) => redisClient.spop(key, callback);

    return module;
};
/* eslint-enable */

